/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package drinkcounter.web.servlet.ui;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import drinkcounter.DrinkCounterService;
import drinkcounter.model.Participant;
import drinkcounter.web.servlet.ParticipantHelper;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Toni
 */
@Singleton
public class AddParticipantServlet extends HttpServlet{

    @Inject private DrinkCounterService service;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Participant participant = ParticipantHelper.parseNewParticipant(req);
        String partyId = req.getParameter("partyId");
        service.addParticipant(participant, partyId);
        resp.sendRedirect("/viewParty?id="+partyId);
    }

}
